package com.gjt.dlmall.product.app;

import java.util.Arrays;
import java.util.Map;

import com.gjt.dlmall.product.vo.AttrRespVo;
import com.gjt.dlmall.product.vo.AttrVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.gjt.dlmall.product.service.AttrService;
import com.gjt.common.utils.PageUtils;
import com.gjt.common.utils.R;



/**
 * 属性表
 *
 * @author gjt
 * @email g45852139@163.com
 * @date 2021-09-02 23:10:21
 */
@RestController
@RequestMapping("product/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;

    /**
     * 列表
     * 请求路劲 /product/attr/base/list/{categoryId}  分页处查询，模糊查询 基本属性
     * 请求路劲 /product/attr/sale/list/{categoryId}  分页处查询，模糊查询 销售属性
     */
//    @RequestMapping("/list")
//    //@RequiresPermissions("product:attr:list")
//    public R list(@RequestParam Map<String, Object> params){
//        PageUtils page = attrService.queryPage(params);
//
//        return R.ok().put("page", page);
//    }
    @RequestMapping("/{attrType}/list/{categoryId}")
    //@RequiresPermissions("product:attr:list")
    public R list(@RequestParam Map<String, Object> params,@PathVariable("categoryId") Long categoryId,@PathVariable("attrType") String attrType){
        PageUtils page = attrService.queryBaseAttrPage(params,categoryId,attrType);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
   /* @RequestMapping("/info/{id}")
    //@RequiresPermissions("product:attr:info")
    public R info(@PathVariable("id") Long id){
		AttrEntity attr = attrService.getById(id);

        return R.ok().put("attr", attr);
    }*/
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("product:attr:info")
    public R info(@PathVariable("id") Long id){
        AttrRespVo attrRespVo = attrService.getAttrInfo(id);
        System.out.println(attrRespVo);
        return R.ok().put("attr", attrRespVo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:attr:save")
    public R save(@RequestBody AttrVo attrVo){
		attrService.saveAttr(attrVo);

        return R.ok();
    }

    /**
     * 修改  提交操作
     */
    //@RequestMapping("/update")
    //@RequiresPermissions("product:attr:update")
//    public R update(@RequestBody AttrEntity attr){
//		attrService.updateById(attr);
//
//        return R.ok();
    @RequestMapping("/update")
    //@RequiresPermissions("product:attr:update")
    public R update(@RequestBody AttrVo attrVo){
		attrService.updateAttr(attrVo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:attr:delete")
    public R delete(@RequestBody Long[] ids){
		attrService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
